package com.lanyou.esb.redis.proxy.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.lanyou.esb.common.CommonUtils;
import com.lanyou.esb.common.Constants4Redis;
import com.lanyou.esb.redis.proxy.base.BaseHashJedisProxy;
import com.lanyou.esb.redis.vo.IfReqQuantityVo;

/**
 * 接口请求量控制Redis操作代理
 * 
 * @author Davey.wu
 */
@Service
public class IfReqQuantityJedisProxy extends
		BaseHashJedisProxy<IfReqQuantityVo> {

	public IfReqQuantityJedisProxy() {
		this.setHashKey(Constants4Redis.REDIS_HASH_KEY_IRQ);
		Map<String, Integer> keyFields = new HashMap<>();
		/** field的组成：接口标识，请求时间单位 **/
		keyFields.put(CommonUtils.INTERFACE_ID, 0);
		keyFields.put(CommonUtils.REQUEST_UNIT, 1);
		this.setKeyFields(keyFields);
	}

	@Override
	public Map<String, String> getKeyMap(IfReqQuantityVo target) {
		Map<String, String> map = new HashMap<>(4);
		map.put(CommonUtils.INTERFACE_ID, target.getIfId());
		map.put(CommonUtils.REQUEST_UNIT, target.getReqUnit());
		return map;
	}
}
